<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible"
    >
    <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="项目编号" prop="workOrderNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.workOrderNumber" placeholder="请填写项目编号"     disabled=""></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="项目名称" prop="roadworkContent"
                :rules="[
                 ]">
              <el-input v-model="inputForm.roadworkContent" placeholder="请填写项目名称"     disabled=""></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="提出人" prop="peopleName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.peopleName" placeholder="请填写提出人"     disabled=""></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工号" prop="workNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.workNumber" placeholder="请填写工号"     disabled=""></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工时" prop="workTime"
                :rules="[
                 ]">
              <el-input v-model="inputForm.workTime" placeholder="请填写工时"     disabled=""></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="状态" prop="state"
                :rules="[
                 ]">
              <el-input v-model="inputForm.state" placeholder="请填写状态"     disabled=""></el-input>
           </el-form-item>
        </el-col>
        <!-- <el-col :span="12">
            <el-form-item label="项目协办人" prop="projectMan"
                :rules="[
                 ]">
              <el-input v-model="inputForm.projectMan" placeholder="请填写项目协办人"     disabled=""></el-input>
           </el-form-item>
        </el-col> -->
        <el-col :span="12">
            <el-form-item label="项目协办人" prop="projectMan"
                :rules="[
                 ]">
                 <el-input v-model="inputForm.projectMan" placeholder="请填写项目协办人"     disabled=""></el-input>
              <user-select :limit='10' :value="inputForm.projectMan" @getValue='(value) => {inputForm.projectMan=value}' @getUserName='getUserName(arguments)' disabled></user-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
                    <el-form-item label="检修标准工时" prop="overhaulPeople"
                        :rules="[
                         ]">
                      <el-input v-model="inputForm.overhaulPeople" placeholder="请填写检修标准工时" disabled=""></el-input>
                   </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="检修标准项目承办人数" prop="repirpeople"
                        :rules="[
                         ]">
                      <el-input v-model="inputForm.repirpeople" placeholder="请填写检修标准项目承办人数" disabled=""></el-input>
                   </el-form-item>
                </el-col>
        <el-col :span="12">
            <el-form-item label="必要性描述" prop="repairDescribe"
                :rules="[
                 ]">
              <el-input v-model="inputForm.repairDescribe" placeholder="请填写必要性描述"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="机具名称" prop="repairName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.repairName" placeholder="请填写机具名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="型号" prop="repairType"
                :rules="[
                 ]">
              <el-input v-model="inputForm.repairType" placeholder="请填写型号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="数量" prop="repairAmount"
                :rules="[
                 ]">
              <el-input v-model="inputForm.repairAmount" placeholder="请填写数量"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="入场时间" prop="repairStartTime"
                :rules="[
                 ]">
              <!-- <el-input v-model="inputForm.repairTime" placeholder="请填写要求使用时间"     ></el-input> -->
              <el-date-picker
                    style="width:100%;"
                    v-model="inputForm.repairStartTime"
                    type="datetime"
                    placeholder="选择日期时间"
                    default-time="12:00:00" >
              </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="完成时间" prop="repairEndTime"
                :rules="[
                 ]">
              <!-- <el-input v-model="inputForm.repairTime" placeholder="请填写要求使用时间"     ></el-input> -->
              <el-date-picker
                    style="width:100%;"
                    v-model="inputForm.repairEndTime"
                    type="datetime"
                    placeholder="选择日期时间"
                    default-time="12:00:00" >
              </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button :disabled="method === 'changestate'" @click="visible = false">关闭</el-button>
      <el-button :disabled="method === 'changestate'" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
    </el-dialog>
</div>
</template>

<script>
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          workOrderNumber: '',
          roadworkContent: '',
          peopleName: '',
          workNumber: '',
          repairDescribe: '',
          repairName: '',
          repairType: '',
          repairAmount: '',
          repairStartTime: '',
          repairEndTime: '',
          remarks: '',
          workTime: '',
          state: '',
          projectMan: '',
          unsuccessfulPeople: '',
          testId: '',
          checkTime: '',
          checkPeopleNumber: '',
          repirpeople: '',
          overhaulPeople: '',
          processId: ''
        },
        loginName: ''
      }
    },
    components: {
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        this.$http({
           url: `/sys/log/logId`,
           method: 'get'
         }).then(({data}) => {
          this.loginName = data.logId.roleNames
        // if (this.loginName !== '项目负责人' && method !== 'view') {
        //   this.$alert('您没有此权限', '提示', {
        //     confirmButtonText: '确定',
        //     type: 'warning'
        //   })
        // } else {
        if (method === 'add') {
          this.title = `新建工器具准备`
        } else if (method === 'edit') {
          this.title = '修改工器具准备'
        } else if (method === 'view') {
          this.title = '查看工器具准备'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view' || method === 'changestate') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/flowform/form/repairBigPlan/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.repairBigPlan)
              if (method === 'changestate') {
                this.inputForm.state = 1
                this.doSubmit()
              }
              this.loading = false
            })
          }
        })
        // }
        })
      },
      // 表单提交
      doSubmit () {
        this.$http({
          url: `/flowform/process/repairTaskDistributionProcess/flowableupdata`,
          method: 'get',
          params: {
            testId: this.inputForm.testId,
            key: 'repair_describe',
            value: this.inputForm.repairDescribe
          }
        })
        this.$http({
          url: `/flowform/process/repairTaskDistributionProcess/flowableupdata`,
          method: 'get',
          params: {
            testId: this.inputForm.testId,
            key: 'repair_name',
            value: this.inputForm.repairName
          }
        })
        this.$http({
          url: `/flowform/process/repairTaskDistributionProcess/flowableupdata`,
          method: 'get',
          params: {
            testId: this.inputForm.testId,
            key: 'repair_type',
            value: this.inputForm.repairType
          }
        })
        this.$http({
          url: `/flowform/process/repairTaskDistributionProcess/flowableupdata`,
          method: 'get',
          params: {
            testId: this.inputForm.testId,
            key: 'repair_amount',
            value: this.inputForm.repairAmount
          }
        })
        this.$http({
          url: `/flowform/process/repairTaskDistributionProcess/flowableupdata`,
          method: 'get',
          params: {
            testId: this.inputForm.testId,
            key: 'repair_amount',
            value: this.inputForm.repairAmount
          }
        })
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/flowform/form/repairBigPlan/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>
